public class BinarySearchTree {

    static class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    public TreeNode root ;

    public void insert(int key) {
        if(root==null){
            root=new TreeNode(key);
            return;
        }
        TreeNode parent=null;
        TreeNode cur=root;
        while (cur!=null){
            parent=cur;
            if(key>cur.val){
                cur=cur.right;
            }
            else if(key<cur.val){
                cur=cur.left;
            }
            else {
                return;
            }
        }
        if(key>parent.val){
            parent.right=new TreeNode(key);
        }
        else if(key< parent.val){
            parent.left=new TreeNode(key);
        }
        else {
            return;
        }
    }
    public void remove(int key){
        TreeNode cur=root;
        TreeNode parent=null;
        while (cur!=null){
            if(key>cur.val){
                parent=cur;
                cur=cur.right;
            }
            else if(key<cur.val){
                parent=cur;
                cur=cur.left;
            }
            else {
                removeCode(parent,cur);
            }
        }
    }

    private void removeCode(TreeNode parent, TreeNode cur) {

    }

    public TreeNode search(int val) {
        if(root==null){
            return null;
        }
        TreeNode cur=root;
        while (cur!=null){
            if(val>cur.val){
                cur=cur.right;
            }
            else if(val<cur.val){
                cur=cur.left;
            }
            else {
                return cur;
            }
        }
        return null;
    }

}